﻿<?php
defined("_VALID_ACCESS") || die('Direct access forbidden');
class SCTV_WarehouseInstall extends ModuleInstall { 
    public function install() {
 
	Base_ThemeCommon::install_default_theme($this->get_type());
	
	$fields = array(
		array('name'=>_M('Delivery Date'), 'type'=>'date', 'required'=>true, 'visible'=>true),
		//array('name'=>_M('Code'), 'type'=>'text', 'param'=>256, 'required'=>true, 'visible'=>true),
		array('name'=>_M('Employee'), 'type'=>'crm_contact', 'param'=>array('field_type'=>'select', 'crits'=>array(), 'format'=>array('CRM_ContactsCommon','contact_format_default')), 'required'=>true, 'visible'=>true),
		array('name'=>_M('Note'), 'type'=>'text', 'param'=>256, 'required'=>false, 'visible'=>true)
	);
	
	Utils_RecordBrowserCommon::install_new_recordset('SCTV_DeliveryToEmployee', $fields);
	Utils_RecordBrowserCommon::set_caption('SCTV_DeliveryToEmployee', _M('Delivery To Employee'));
	Utils_RecordBrowserCommon::add_default_access('SCTV_DeliveryToEmployee');
	
	$fields = array(
			array('name'=>_M('Delivery'), 'type'=>'select', 'param'=>array('SCTV_DeliveryToEmployee'=>'id'), 'required'=>true, 'visible'=>false),
			array('name'=>_M('Material'), 'type'=>'select', 'param'=>array('SCTV_Material'=>'Material Code|Material Name'), 'required'=>true, 'visible'=>true),					
			array('name'=>_M('Amount'), 'type'=>'integer', 'required'=>true, 'visible'=>true),																							
			array('name'=>_M('Note'), 'type'=>'text', 'param'=>256, 'required'=>false, 'visible'=>true)			
		);
	
	Utils_RecordBrowserCommon::install_new_recordset('SCTV_DeliveryMaterial', $fields);
	Utils_RecordBrowserCommon::set_caption('SCTV_DeliveryMaterial', _M('Delivery Material'));
	Utils_RecordBrowserCommon::add_default_access('SCTV_DeliveryMaterial');
	
	Utils_RecordBrowserCommon::new_addon('SCTV_DeliveryToEmployee', 'SCTV_Warehouse', 'delivery_material_addon', _M('Material'));
	
	// Receive
	$fields = array(
		array('name'=>_M('Receive Date'), 'type'=>'date', 'required'=>true, 'visible'=>true),
		//array('name'=>_M('Code'), 'type'=>'text', 'param'=>256, 'required'=>true, 'visible'=>true),
		array('name'=>_M('Employee'), 'type'=>'crm_contact', 'param'=>array('field_type'=>'select', 'crits'=>array(), 'format'=>array('CRM_ContactsCommon','contact_format_default')), 'required'=>true, 'visible'=>true),
		array('name'=>_M('Note'), 'type'=>'text', 'param'=>256, 'required'=>false, 'visible'=>true)
	);
	
	Utils_RecordBrowserCommon::install_new_recordset('SCTV_ReceiveFromEmployee', $fields);
	Utils_RecordBrowserCommon::set_caption('SCTV_ReceiveFromEmployee', _M('Receive From Employee'));
	Utils_RecordBrowserCommon::add_default_access('SCTV_ReceiveFromEmployee');
	
	$fields = array(
			array('name'=>_M('Receive'), 'type'=>'select', 'param'=>array('SCTV_ReceiveFromEmployee'=>'id'), 'required'=>true, 'visible'=>false),
			array('name'=>_M('Material'), 'type'=>'select', 'param'=>array('SCTV_Material'=>'Material Code|Material Name'), 'required'=>true, 'visible'=>true),					
			array('name'=>_M('Amount'), 'type'=>'integer', 'required'=>true, 'visible'=>true),																							
			array('name'=>_M('Note'), 'type'=>'text', 'param'=>256, 'required'=>false, 'visible'=>true)			
		);
	
	Utils_RecordBrowserCommon::install_new_recordset('SCTV_ReceiveMaterial', $fields);
	Utils_RecordBrowserCommon::set_caption('SCTV_ReceiveMaterial', _M('Delivery Material'));
	Utils_RecordBrowserCommon::add_default_access('SCTV_ReceiveMaterial');
	
	Utils_RecordBrowserCommon::new_addon('SCTV_ReceiveFromEmployee', 'SCTV_Warehouse', 'receive_material_addon', _M('Material'));
	
	$fields = array(
			array('name'=>_M('Year'), 'type'=>'integer', 'required'=>true, 'visible'=>true),
			array('name'=>_M('Month'), 'type'=>'integer', 'required'=>true, 'visible'=>true),
			array('name'=>_M('Employee'), 'type'=>'crm_contact', 'param'=>array('field_type'=>'select', 'crits'=>array(), 'format'=>array('CRM_ContactsCommon','contact_format_default')), 'required'=>true, 'visible'=>true),
			array('name'=>_M('Material'), 'type'=>'select', 'param'=>array('SCTV_Material'=>'Material Code|Material Name'), 'required'=>true, 'visible'=>true),					
			array('name'=>_M('Amount'), 'type'=>'integer', 'required'=>true, 'visible'=>true)																									
		);
	
	Utils_RecordBrowserCommon::install_new_recordset('SCTV_EmployeeInventory', $fields);
	Utils_RecordBrowserCommon::set_caption('SCTV_EmployeeInventory', _M('Employee Inventory'));
	Utils_RecordBrowserCommon::add_default_access('SCTV_EmployeeInventory');
	
    return true;
    }
 
    public function uninstall() {
		Base_ThemeCommon::uninstall_default_theme($this->get_type());
		
		Utils_RecordBrowserCommon::uninstall_recordset('SCTV_DeliveryToEmployee');
		Utils_RecordBrowserCommon::uninstall_recordset('SCTV_DeliveryMaterial');
		
		Utils_RecordBrowserCommon::uninstall_recordset('SCTV_ReceiveFromEmployee');
		Utils_RecordBrowserCommon::uninstall_recordset('SCTV_ReceiveMaterial');
				
		return true;
    }
 
    public function info() {
        return array( 'Author'=>'Pham Huu Le Quoc Phuc', 'License'=>'SCTV', 'Description'=>'Warehouse');
    }
 
    public function simple_setup() {
        return array('package' => __('Warehouse'), 'version'=>'1.0');
    }
 
    public function requires($v) {
        return array();
    }
 
    public function version() {
        return array('1.0');
    }
}
 
?>